<template>
  <div class="totalPower">
      <titlePons text="总用电量" />
    <div id="echartTotalPower"></div>
  </div>
</template>

<script>
import titlePons from "./titlePons.vue";
export default {
  name: "totalPower",
  components: {
    titlePons,
  },
  data() {
    return {
      bg: require("@/assets/images/DispatchCommand/stitle.png"),
    };
  },
  mounted() {
    this.setEchart();
  },
  methods: {
    setEchart() {
      const _echarts = this.$echarts.init(
        document.getElementById("echartTotalPower")
      );
      const option = {
        tooltip: {
          trigger: "axis",
        },
        xAxis: {
          type: "category",
          data: [
            "1月",
            "2月",
            "3月",
            "4月",
            "5月",
            "6月",
            "7月",
            "8月",
            "9月",
            "10月",
            "11月",
            "12月",
          ],
          axisLine: {
            lineStyle: {
              color: "#fff",
            },
          },
          axisLabel: {
            textStyle: {
              color: "#fff",
              fontSize: 12,
            },
          },
        },
        yAxis: {
          type: "value",
          name: "( KWH )",
          axisLabel: {
            formatter: "{value}",
            textStyle: {
              color: "#fff",
              fontSize: 12,
            },
          },
          axisLine: {
            lineStyle: {
              color: "#fff",
            },
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: ["#305383"],
              width: 1,
              type: "solid",
            },
          },
        },
        grid: {
          top: "20%",
          bottom: "15%",
          right: "5%",
        },
        series: [
          {
            data: [10, 20, 10, 8, 7, 11, 13, 12, 34, 51, 2, 12],
            type: "bar",
            barWidth: 20,
            itemStyle: {
              normal: {
                color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  { offset: 0, color: "rgba(34, 154, 255, 1)" }, //柱图渐变色
                  { offset: 0.5, color: "rgba(34, 154, 255, 0.7)" }, //柱图渐变色
                  { offset: 1, color: "rgba(34, 154, 255, 0.3)" }, //柱图渐变色
                ]),
              },
            },
          },
        ],
      };
      _echarts.setOption(option);
    },
  },
};
</script>

<style lang="scss" scoped>
.totalPower {
  width: 600px;
  float: left;
  box-sizing: border-box;
  #echartTotalPower {
    width: 100%;
    height: 200px;
  }
}
</style>
